<?php

class RoleModel extends MCActiveRecord
{
	protected $_table = 'roles';
	protected $_id = 'role_id';
	
	/**
	 * 保存角色
	 * @param string $role_name
	 * @param array $rights
	 * @param int $role_id
	 * @return boolean
	 */
	public function role_save($role_name, $rights, $role_id = 0)
	{
		$role_id = (int) $role_id;
		$this->role_name = $role_name;
		$this->act_rights = json_encode($rights);
		
		if ($role_id > 0)
		{
			$this->role_id = $role_id;
			$this->setIsNewRecord(false);
		}
		return $this->save();
	}
}